package com.frank.yinyuetai.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.frank.yinyuetai.Bean.VideoBean;
import com.frank.yinyuetai.R;

import java.util.List;

/**
 * Created by Administrator on 2016/8/18 0018.
 */
public class MvListViewAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    private Context context;
    private List<VideoBean> mList;

    public MvListViewAdapter(Context context, List<VideoBean> mList) {
        this.context = context;
        this.mList = mList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (view == null) {
            viewHolder = new ViewHolder();
            view = inflater.inflate(R.layout.mv_recycleview_item, null);
            viewHolder.name = (TextView) view.findViewById(R.id.name);
            viewHolder.playCount = (TextView) view.findViewById(R.id.play_count);
            viewHolder.author = (TextView) view.findViewById(R.id.author);
            viewHolder.posterImg = (ImageView) view.findViewById(R.id.poster_img);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        VideoBean videoBean = mList.get(i);
        viewHolder.name.setText(videoBean.getTitle());
        viewHolder.author.setText(videoBean.getDescription());
        if (videoBean.isAd()) {
            Glide.with(context).load(videoBean.getThumbnailPic()).diskCacheStrategy(DiskCacheStrategy.ALL).into(viewHolder.posterImg);
            viewHolder.playCount.setText("");
        } else {
            Glide.with(context).load(videoBean.getAlbumImg()).diskCacheStrategy(DiskCacheStrategy.ALL).into(viewHolder.posterImg);
            viewHolder.playCount.setText("播放次数：" + videoBean.getTotalViews());
        }

        return view;
    }
}

class ViewHolder {
    public ImageView posterImg;
    public TextView name, author, playCount;
}